package com.keshan.service.impl;

import com.keshan.mapper.SleepMapper;
import com.keshan.pojo.Sleep;
import com.keshan.pojo.SleepEverydayData;
import com.keshan.utils.DateUtil;
import com.keshan.pojo.SleepHide;
import com.keshan.service.SleepServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author keshan
 * @date 2022/10/21 - 19:40
 */
@Service
public class SleepServicesImpl implements SleepServices {
    @Autowired
    SleepMapper sleepMapper;
    @Override
    public int insertBySelectiveSleep(Sleep sleep) {
        return sleepMapper.insertSelective(sleep);
    }

//    @Override
//    public List<Sleep> getSleepListByImeiToday(String imei) {
//        SleepExample sleepExample = new SleepExample();
//        SleepExample.Criteria criteria = sleepExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        List<Date> dateList = DateUtil.getStartAndEndToday();
//        criteria.andTimeEndBetween(dateList.get(0),dateList.get(1));
//        List<Sleep> sleepList = sleepMapper.selectByExample(sleepExample);
//        return sleepList;
//    }
//
//    @Override
//    public List<SleepHide> getSleepListHideByImei(String imei) {
//        SleepExample sleepExample = new SleepExample();
//        SleepExample.Criteria criteria = sleepExample.createCriteria();
//        criteria.andImeiEqualTo(imei);
//        return sleepMapper.selectHideByExample(sleepExample);
//    }

    @Override
    public List<SleepHide> getSleepListHideByUsernameToday(String username) {
        List<Date> dateList = DateUtil.getStartAndEndToday();
        return sleepMapper.selectHideByExample(dateList.get(0),dateList.get(1),username);
    }

    @Override
    public List<SleepEverydayData> getSleepEverydayDataList(String username) {
        List<Date> dateList = DateUtil.getStartAndEndTwoMonth();
        System.out.println(dateList.toString());
        return sleepMapper.selectSleepEverydayData(dateList.get(0),dateList.get(1),username);
    }
}
